<template>
	<!-- 回收员订单组件 -->
	<view class="completed">
		<view class="completed-main" v-for="(item,index) in orderList" :key="index">
			<view class="radio" v-show="!ispack" @tap="choice(item)">
				<image v-show="item.ischoice"
					src="https://huishou.68699.cn/addons/wjyk_recycle/public/static/index/true.png" mode=""></image>
			</view>
			<!-- {{item.ischoice}} -->
			<view class="completed-main-content" @tap="inOrderDetail(item.id)">
				<view class="addressibfo-header" v-if="tabbarIndex==1">
					<view class="recycler">客户信息</view>
					<view class="hsyInfo">
						<text class="name">{{item.consignee}}</text>
						<text class="hsyPhone">{{item.consignee_phone}}</text>
					</view>
					<view class="right" @click.stop="call(item)">
						<view class="phone">呼叫</view>
					</view>
				</view>
				<view class="addressinfo">
					<view class="address-text">
						<view class="addressinfo-title">上门地址</view>
						<view class="text">{{item.location}}{{item.detail}}</view>
					</view>
					<view class="icon iconfont icon-xiangyoujiantou"></view>
				</view>
				<view class="addressText-coins">
					<view class="coins-title">预约时间</view>
					<view class="coins">{{item.createtime}}</view>
				</view>
				<view class="orderButton" v-if="tabbarIndex==1">
					<view class="sour" @click.stop="confirm(item.id)">回收确认</view>
					<view class="cancel" @click.stop="cancelOrder(item.id)">取消</view>
				</view>
				<view class="offerTime" v-if="tabbarIndex==2">
					<text class="offerTime-text">出价时间</text>
					<text class="time">{{item.finishtime}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import util from "@/component/commen/api/util.js"
	export default {
		props: {
			orderList: Array,
			tabbarIndex: String,
			ispack: Boolean,
		},
		data() {
			return {
				ischoice: false, //是否选中
			}
		},
		watch: {
			orderList(value) {
				console.log("子组件中的值", value)
			}
		},
		mounted() {
			console.log("aaaa", this.orderList)
		},
		methods: {
			inOrderDetail(value) { //点击进入订单详情
				uni.navigateTo({
					url: `/otherPages/recoverDetail/recoverDetail?orderId=${this.tabbarIndex}&orderDetailId=${value}`
				})
			},
			cancelOrder(id) {
				var that = this
				var params = {
					do: "collector",
					op: "cancel",
					id: id
				}
				util.requestWithSign(params).then(res => {
					console.log("取消")
					if (res.errno == 0) {
						uni.showModal({
							title: res.message,
							showCancel: false,
							success() {
								that.$emit("cancelEnd", 1)
							}
						})
					}
				})
				// 阻止事件冒泡
			},
			choice(item) { //点击选择
				item.ischoice = !item.ischoice
				console.log(this.orderList)
				this.$emit("updateshoice", this.orderList)
			},
			confirm(id) { //点击回收确认
				uni.navigateTo({
					url: `/otherPages/RecycleConfirm/RecycleConfirm?orderId=${id}`
				})
				// 阻止事件冒泡
			},
			call(item) { //点击呼叫
				console.log("点击呼叫", item)
				uni.makePhoneCall({
					phoneNumber:item.consignee_phone, // 拨打的电话号码
					success() {
						console.log('拨打电话成功');
					},
					fail(error) {
						console.error('拨打电话失败:', error.errMsg);
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.completed {
		.completed-main {
			margin-top: 20rpx;
			display: flex;
			align-items: center;

			.radio {
				width: 40rpx;
				height: 40rpx;
				border: 2rpx solid #00b388;
				background: #fff;
				margin-right: 20rpx;
				border-radius: 50%;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.completed-main-content {
				width: 100%;
			}
		}

		.addressibfo-header {
			font-size: 26rpx;
			color: #fff;
			// margin-top: 20rpx;
			padding: 20rpx;
			box-sizing: border-box;
			border-radius: 20rpx 20rpx 0 0;
			display: flex;
			// border: 1px solid #000;
			justify-content: space-between;
			background: #00b388;

			.recycler {
				width: 120rpx;
				// border: 1px solid #000;
			}

			.hsyInfo {
				text-align: center;

				// border: 1px solid #f00;
				.name {
					margin-right: 10rpx;
				}
			}

			.right {

				// margin-left: auto;
				// border: 1px solid #ccc;
				.phone {
					width: 100rpx;
					height: 50rpx;
					line-height: 50rpx;
					text-align: center;
					color: #00b388;
					background: #f7f7f7;
					border-radius: 10rpx;
				}
			}
		}

		.addressinfo {
			background: #fff;
			padding: 20rpx;
			// margin-top: 20rpx;
			// border-radius: 20rpx 20rpx 0 0;

			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.address-text {
				display: flex;
				width: 80%;

				.addressinfo-title {
					width: 160rpx;
					font-size: 25rpx;
					color: #6c6c6c;
					// border: 1px solid #4fc3a5;
				}

				.text {
					font-size: 28rpx;
					margin-left: 20rpx;
				}

			}


			.icon-xiangyoujiantou {
				// flex:1;
				margin-left: auto;
			}
		}

		.addressText-coins {
			display: flex;
			background: #fff;
			padding: 20rpx;
			box-sizing: border-box;
			border-bottom: 2rpx solid #f0f0f0;

			// margin-top: 20rpx;
			.coins-title {
				width: 120rpx;
				font-size: 25rpx;
				color: #6c6c6c;
			}

			.coins {
				// color: #ffc506;
				font-weight: bold;
			}
		}

		.orderButton {
			display: flex;
			background: #fff;
			padding: 20rpx;
			box-sizing: border-box;
			justify-content: flex-end;

			.sour,
			.cancel {
				width: 130rpx;
				height: 45rpx;
				line-height: 45rpx;
				text-align: center;
				border-radius: 10rpx;
			}

			.sour {
				margin-right: 20rpx;
				border: 2rpx solid #00b388;
				color: #00b388;
			}

			.cancel {
				background: #f0f0f0;
				color: #f00;
			}
		}

		.offerTime {
			//出价时间
			font-size: 25rpx;
			color: #6c6c6c;
			background: #fff;
			padding: 20rpx;
			box-sizing: border-box;

			.offerTime-text {
				display: inline-block;
				margin-right: 30rpx;
			}
		}
	}
</style>